package cn.tedu.springboot.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

//本类是用来测试查询业务的演示demo
public class TestSelect {
    //查询location中的所有数据
    private static Connection conn = null;
    private static PreparedStatement ps = null;
    public static void main(String[] args) throws Exception {
        Class.forName("com.mysql.jdbc.Driver");
        String url = "jdbc:mysql://localhost:3306/tedu?useUnicode=true&characterEncoding=utf8";
        String user = "root";
        String pwd = "root";
        conn = DriverManager.getConnection(url, user, pwd);
        String sql = "SELECT id,name FROM location";
        ps = conn.prepareStatement(sql);
        ResultSet rs = ps.executeQuery();
        while (rs.next()){
            int id = rs.getInt("id");
            String name =rs.getString("name");
            System.out.println(id + "\t" + name);
        }
        rs.close();
        ps.close();
        conn.close();

    }
}
